﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace DSS_Simplex
{
    public partial class OpenDB : Form
    {
        private static MySqlConnection connection;
        private static string ConnectionString = "Server=localhost;Database=dss;Uid=root;Pwd=;";

        public OpenDB()
        {
            InitializeComponent();
            connection = new MySqlConnection(ConnectionString);
            MySqlCommand cmd = new MySqlCommand("SELECT * FROM `project`",connection);

            MySqlDataAdapter da = new MySqlDataAdapter(cmd);
            DataTable table = new DataTable("myTable");
            da.Fill(table);
            listView1.View = View.Details;
            ListViewItem iItem;
            foreach (DataRow row in table.Rows)
            {
                iItem = new ListViewItem();
                for (int i = 0; i < row.ItemArray.Length; i++) 
                {
                    if (i == 0)
                        iItem.Text = row.ItemArray[i].ToString();
                    else
                        iItem.SubItems.Add(row.ItemArray[i].ToString());
                }
                listView1.Items.Add(iItem);
            }

            listView1.Columns[0].Width = 0;

            
        }

        private void OpenDB_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'projDataSet.project' table. You can move, or remove it, as needed.
            

        }

        private void listView1_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                
                textBox1.Text = listView1.SelectedItems[0].SubItems[0].Text;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        
        private void listView1_Click(object sender, EventArgs e)
        {
            textBox2.Text = listView1.SelectedItems[0].SubItems[1].Text;
            textBox1.Text = listView1.SelectedItems[0].SubItems[0].Text;
        }

        public string getTextBoxValue()
        {
            return textBox1.Text;
        }

    }
}
